package com.dinadi.yidi.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.dinadi.yidi.R;
import com.dinadi.yidi.bean.MyFollowsRequestEntity;
import com.dinadi.yidi.ui.activity.DesignerHmePageActivity;
import com.dinadi.yidi.utils.ImageUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * author: JiaYu.He
 * Date: 2017/3/22
 * Time: 15:19
 */

public class MyFollowsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    Context mContext;
    List<MyFollowsRequestEntity> mDatas = new ArrayList<>();

    public void addAllData(List<MyFollowsRequestEntity> dataList) {
        this.mDatas.addAll(dataList);
        notifyDataSetChanged();
    }

    public void clearData() {
        this.mDatas.clear();
    }

    public MyFollowsAdapter(Context context) {
        mContext = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_my_follows_item, parent, false);
        return new MyFollowsAdapter.ItemViewHolder(v);

    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {

        ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
        itemViewHolder.text_msg.setText(mDatas.get(position).getNickName());
        itemViewHolder.text_content.setText(mDatas.get(position).getSignature());
        String imgUrl = mDatas.get(position).getHeadImg();
        if (imgUrl != null) {
            if (!imgUrl.equals("")) {
                ImageUtils.loadImageView(mContext, imgUrl, itemViewHolder.imageView);
            } else {
                ImageUtils.loadImageView(mContext, R.drawable.symbols_bitmap, itemViewHolder.imageView);
            }
        }else{
            ImageUtils.loadImageView(mContext, R.drawable.symbols_bitmap, itemViewHolder.imageView);

        }
//        String isVip = mDatas.get(position).getIsVip();
//        if (isVip.equals("0")) {
//            itemViewHolder.whether_authentication.setVisibility(View.GONE);
//
//        } else {
//            itemViewHolder.whether_authentication.setVisibility(View.VISIBLE);
//        }
        String lable = mDatas.get(position).getLable();//0  否   1  是
        if(lable != null ){
            if (lable.equals("3")) {
            /*认证*/
                itemViewHolder.whether_authentication.setImageResource(R.drawable.designer_brand_icon_authentication);
            } else if (lable.equals("1")) {
            /*推荐 */
                itemViewHolder.whether_authentication.setImageResource(R.drawable.designer_brand_icon_recommend);
            } else if (lable.equals("2")) {
            /*中国样 */
                itemViewHolder.whether_authentication.setImageResource(R.drawable.designer_brand_icon_zhongguoyang);
            }
        }else {
            itemViewHolder.whether_authentication.setImageResource(R.drawable.designer_brand_icon_authentication);
        }

        itemViewHolder.user_information.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(mContext, DesignerHmePageActivity.class);
                intent.putExtra("dUserId", mDatas.get(position).getUserId());
                intent.putExtra("type", mDatas.get(position).getType());
                mContext.startActivity(intent);
            }
        });


    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }


    public class ItemViewHolder extends RecyclerView.ViewHolder {

        TextView text_msg, text_content;
        ImageView imageView, whether_authentication;
        RelativeLayout user_information;

        public ItemViewHolder(View itemView) {
            super(itemView);
            text_msg = (TextView) itemView.findViewById(R.id.text_msg);
            text_content = (TextView) itemView.findViewById(R.id.text_content);
            imageView = (ImageView) itemView.findViewById(R.id.img_msg);
            whether_authentication = (ImageView) itemView.findViewById(R.id.whether_authentication);
            user_information= (RelativeLayout) itemView.findViewById(R.id.user_information);
            //initListener(itemView);
        }

        private void initListener(View itemView) {
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(mContext, "poistion " + getAdapterPosition(), Toast.LENGTH_SHORT).show();
                }
            });
        }
    }


}

